<?php

namespace App\Api\Controllers;

/* use App\Http\Controllers\Controller; */
use Illuminate\Http\Request;
use App\Http\Controllers\Api\BaseController;


class HcUploadController extends BaseController
{
   /**
    * 单文件上传
    * 
    * @param hc_file 文件名
    */
    public function upload(Request $request){
        
        if(!empty($hc_file = $request->file('hc_file'))){
            
            $imgs_str = '';
            
            foreach ($hc_file as $key=>$vfile){
            
                $key=$key+1;
            
                if($vfile->isValid()){
            
                    $path = $vfile->store('huace/hc_file/'.date('Y').'-'.date('m').'-'.date('d'));
                    $path = '/uploads/'.$path;
                    $imgs_str .=$path.',';
                    
                }else{
            
                    return response()->json(['code'=>1,'msg'=>'第'.$key.'图片上传失败','data'=>'']);
                }
                 
            }
             
            $path = substr($imgs_str,0,strrpos($imgs_str,","));
            
            return response()->json(['code'=>0,'msg'=>'上传成功','data'=>['file_path'=>$path]]);
   
        }

    }
}
